package
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	
	import gzgi.text.TimeFormater;
	
	public class ProjectorLogger extends EventDispatcher implements ILoggerAction
	{
		public static var LOGGER_PATH:String = "/log/";
		private static var m_instance:ProjectorLogger;
		public function ProjectorLogger(target:IEventDispatcher=null)
		{
			super(target);
		}
		public static function getInstance():ILoggerAction
		{
			if (m_instance == null)
			{
				m_instance = new ProjectorLogger();
			}
			return m_instance;
		}
		public function logger($str:String):void
		{
			var date:Date = new Date();
			var formater:TimeFormater = new TimeFormater("system_log_yyyy-MM-dd.log");
			var timeDetailFormater:TimeFormater = new TimeFormater();
			var fileName:String = formater.format(date);
			var path:String = File.applicationDirectory.nativePath + LOGGER_PATH + fileName;
			var file:File = new File(path);
			var fileStream:FileStream = new FileStream();
			fileStream.open(file, FileMode.APPEND);
			fileStream.writeUTF("[" + timeDetailFormater.format(date) + "]\n");
			fileStream.writeUTF($str + "\n");
			fileStream.writeUTF("\n");
			fileStream.close();
		}
	}
}